package com.smi.cn.satemachine;

import org.squirrelframework.foundation.fsm.ImmutableTransition;
import org.squirrelframework.foundation.fsm.UntypedStateMachine;

import java.util.List;

public class StatemachineUtil {
    /**
     * 转换器的描述信息
     */
    public static String getTransitDesc(ReturnVo.RmaStatus to, ReturnVo.RmaTrigger rmaTrigger, UntypedStateMachine stateMachine) {
        String transitDesc = to.getDesc();
        if (stateMachine.getLastRawState() != null) {
            List<ImmutableTransition<UntypedStateMachine, Object, Object, Object>> immutableTransitions = stateMachine.getLastRawState().getTransitions(rmaTrigger);
            if (immutableTransitions != null && immutableTransitions.size() > 0) {
                for (ImmutableTransition transition : immutableTransitions) {
                    if (((ReturnVo.RmaStatus)transition.getTargetState().getStateId()).name().equals(to.name())) {
                        if (transition.getTransitionDesc() != null && transition.getTransitionDesc().length() > 0) {
                            transitDesc = transition.getTransitionDesc();
                        }
                    }
                }
            }
        }
        return transitDesc;
    }
}
